import java.awt.*;

import javax.swing.*;


public class AllPlayerInfoPanel extends Panel
{
	private static final long serialVersionUID = 1L;
	private ImageIcon imgHuman, imgBot, imgDealer, imgSmallBlind, imgBigBlind, imgcardOff, imgcardOn, imgClubMini, imgDiamondMini, imgHeartMini, imgSpadeMini;
	private JLabel playerId, playerName, playerType, card[], playerBet, playerAction, playerTokens;
	private int type, cardRange;
	AllPlayerInfoPanel(int type)
	{
		setBackground(new Color(0,172,15));
		setLayout(new FlowLayout(FlowLayout.LEADING, 5, 4));
		setFont(new Font("Lucida Console", Font.PLAIN, 22));
		imgHuman = new ImageIcon(getClass().getResource("img/human.png"));
		imgBot = new ImageIcon(getClass().getResource("img/bot.png"));
		imgDealer = new ImageIcon(getClass().getResource("img/dealer_button.png"));
		imgSmallBlind = new ImageIcon(getClass().getResource("img/small_blind.png"));
		imgBigBlind = new ImageIcon(getClass().getResource("img/big_blind.png"));
		imgcardOff = new ImageIcon(getClass().getResource("img/cardOff.png"));
		imgcardOn = new ImageIcon(getClass().getResource("img/cardOn.png"));
		imgClubMini = new ImageIcon(getClass().getResource("img/club_mini.png"));
		imgDiamondMini = new ImageIcon(getClass().getResource("img/diamond_mini.png"));
		imgHeartMini = new ImageIcon(getClass().getResource("img/heart_mini.png"));
		imgSpadeMini = new ImageIcon(getClass().getResource("img/spade_mini.png"));
		this.type=type;
		card = new JLabel[4];
		
	}
	void initialize(String sId, String sName, String sTokens)
	{
		playerId = new JLabel(sId+". ");
		playerId.setFont(new Font("Lucida Console", 0, 22));
		playerId.setPreferredSize(new Dimension(40, 32));
		playerName = new JLabel(sName);
		playerName.setFont(new Font("Lucida Console", 0, 22));
		playerName.setPreferredSize(new Dimension(160,32));
		playerType = new JLabel("");
		playerType.setPreferredSize(new Dimension(32, 32));
		if(type==0)
		{
			playerType.setIcon(imgHuman);
		}
		else
		{
			playerType.setIcon(imgBot);
		}
		for(int i=0; i<4; i++)
		{
			card[i] = new JLabel("");
			card[i].setIcon(imgcardOff);
			card[i].setPreferredSize(new Dimension(36, 32));
		}
		playerBet = new JLabel("0");
		playerBet.setFont(new Font("Lucida Console", 0, 22));
		playerBet.setPreferredSize(new Dimension(75, 32));
		playerAction = new JLabel("");
		playerAction.setFont(new Font("Lucida Console", 0, 22));
		playerAction.setPreferredSize(new Dimension(200, 32));
		playerTokens = new JLabel(sTokens+"");
		playerTokens.setFont(new Font("Lucida Console", 0, 22));
		playerTokens.setPreferredSize(new Dimension(90, 32));
		add(playerType);
		add(playerId);
		add(playerName);
		for(int i=0; i<4; i++)
		{
			add(card[i]);
			card[i].setHorizontalTextPosition(SwingConstants.CENTER);
			card[i].setForeground(Color.WHITE);
		}
		add(playerBet);
		add(playerAction);
		add(playerTokens);
		
	}
	void changeType(int tempType)
	{
		if(tempType==1)
		{
			playerType.setIcon(imgDealer);
		}
		else if(tempType==2)
		{
			playerType.setIcon(imgSmallBlind);
		}
		else if(tempType==3)
		{
			playerType.setIcon(imgBigBlind);
		}
		else
		{
			if(type==0)
			{
				playerType.setIcon(imgHuman);
			}
			else
			{
				playerType.setIcon(imgBot);
			}
		}
	}
	void changecards(int[] cards)
	{
		for(int i=0; i<4; i++)
		{
			if(cards[i]==0)
			{
				card[i].setIcon(imgcardOff);
			}
			else if(cards[i]==1)
			{
				card[i].setIcon(imgcardOn);
			}
			card[i].setText("");
		}
	}
	void showcards(String[] cards)
	{
		for(int i=0; i<4; i++)
		{
				if(cards[i].charAt(0)=='C')
				{
					card[i].setIcon(imgClubMini);
				}
				else if(cards[i].charAt(0)=='D')
				{
					card[i].setIcon(imgDiamondMini);
				}
				else if(cards[i].charAt(0)=='H')
				{
					card[i].setIcon(imgHeartMini);
				}
				else if(cards[i].charAt(0)=='S')
				{
					card[i].setIcon(imgSpadeMini);
				}
				card[i].setFont(new Font("Lucida Console", 0, 12));
				try
				{
					cardRange=Integer.parseInt(cards[i].substring(1));
					if(cardRange==1)
					{
						card[i].setText("A");
					}
					else if(cardRange>=2 && cardRange<=10)
					{
						card[i].setText(""+cardRange);
					}
					else if(cardRange==11)
					{
						card[i].setText("J");
					}
					else if(cardRange==12)
					{
						card[i].setText("Q");
					}
					else if(cardRange==13)
					{
						card[i].setText("K");
					}
				}
				catch(NumberFormatException ex)
				{
					System.out.println("Problem z parsowaniem stringa na inta!");
				}
		}
	}
	void hidecards()
	{
		for(int i=0; i<4; i++)
		{
			card[i].setText("");
			card[i].setIcon(imgcardOff);
		}
	}
	void updateBet(String bet)
	{
		playerBet.setText(bet);
	}
	void changeAction(String action)
	{
		playerAction.setText(action);
	}
	void updateTokens(String tokens)
	{
		playerTokens.setText(tokens);
	}
}